#set(SysUser user)
<form action="save" method="post" id="addform">
	<input id="id" name="id" type="hidden" value="${user.get('id')}"/>
	<input id="rights" name="rights" type="hidden" value="${user.get('rights')}"/>
    <p><label>登录账号：</label><input id="username" name="username" type="text" value="${user.get('username')}" required/></p>
	#if(!user)
	<p><label>登录密码：</label><input id="password" name="password" type="password" required/></p>
	#end
	<p><label>账户邮箱：</label><input id="email" name="email" type="email" value="${user.email}" required/></p>
	<p id="radiolist"><label>用户性别：</label>
	<input id="sex0" name="sex" value="0" type="radio" class="radio" required checked="checked"/><label>男</label>
	<input id="sex1" name="sex" value="1" type="radio" class="radio"  required /><label>女</label>
	</p>
	<p>
	<label>用户角色：</label>
	<select name="role" id="role">
		<option value="0">请选择角色</option>
		#for(SysRole r : roles)
		<option value="${r.get('id')}" ${r.get('id')==user.get('role_id')?"selected":""}>${r.get('name')}</option>
		#end
	</select>
	</p>
	<p>
	<label>用户权限：</label>
	<ul id="ztree" class="ztree"></ul>
	</p>
</form>
<style>
<!--
#addform p { padding:5px;  }
#addform input { width:13em; padding:4px; border:1px solid #CCC;}
#addform .radio { width:2em; padding:4px; border:1px solid #CCC; }
#addform input:focus { border-color:#426DC9; }
#addform .login-form-error { background:#FFFBFC; border-color:#F00 !important; }
.input {
	border: 1px solid #999;
	background-color: #fff;
	box-shadow: inset 0 1px rgba(0,0,0,.15);
	padding: 5px;
}
.input[disabled] {
	background-color: #eee;
	box-shadow: none;
}
-->
</style>
<script type="text/javascript">
$("#addform").html5Validate(function(){
	$.ajax({
		url:'save',
		type:'post',
		dataType:'json',
		data:$("#addform").serialize(),
		success:function(d){
			if(d.success){
				$.dialog({title:'提示',content:'操作成功'}).time(3);	
				api.close();
			}else{
				$.dialog({title:'提示',content:d.msg}).time(3);
				api.close();
			}
			reloadMe();
		},
		error:function(){
			$.dialog({title:'提示',content:'操作失败,服务器错误.'}).time(3);	
			api.close();
		}
	});

},{
	validate:function(){
		if($("#role").val()==0){
			alert('请选择角色.');
			return false;
		}
		var zTree = $.fn.zTree.getZTreeObj("ztree"),
		nodes = zTree.getCheckedNodes();
		var ids = new Array();
		for (var i=0, l=nodes.length; i<l; i++) {
			ids.push(nodes[i].id);
		}
		$("#rights").val(ids.join(","));
		return true;
	}
});
var setting = {
    check: {
		enable: true
	},
	data: {
		simpleData: {
			enable: true
		}
	}
};
$('#radiolist').hradio();
$.fn.zTree.init($("#ztree"), setting, $!{menuNodes});
</script>